const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    type:'',
    categoryId:'',
    isselect:false,
    categoryList:[],
    listForLawyer:[],
    page:1,
    pageSize:20,
    isEnd:false,
    isloading:true,
  },
  onLoad(option) {
  
    this.getCategoryList()
    
  },
  onShow(){
   this.setData({
    listForLawyer:[],
    page:1,
    isEnd:false,
    isloading:true
   },()=>{
     this.getlistForLawyer()
   })
  },
  select(){
    this.setData({
      isselect:!this.data.isselect
    })
  },
  selectoption(e){
    this.setData({
      isselect:false,
      type:e.currentTarget.dataset.name,
      categoryId:e.currentTarget.dataset.id
    })
  },
  accept(){
    wx.showModal({
        title: '',
        content: "确定接单吗？",
        confirmColor:'#0557A8',
        cancelColor:'#C2C2C2',
        success (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
  },
  
  golink(e){
    let id=e.target.dataset.id
    let  url=e.currentTarget.dataset.url+`?id=${id}`;
    if (!wx.getStorageSync('logintoken')) {
      app.goLogin(false)
      return
    }
    if(id===0||id){
      wx.navigateTo({
        url
      });
    }
    
  },
  //搜索
  search(){
   this.setData({
    listForLawyer:[],
    page:1,
    isEnd:false
   },()=>{
     this.getlistForLawyer()
   })
  
   
  },
  //获取类型列表
  getCategoryList(){
  Controller.categoryList({}).then(res=>{
    let baseData=res.data.baseData
    
    this.setData({
      categoryList:baseData,
     
    })
  })
  },
  //获取案源池列表
  getlistForLawyer(){
    let categoryId	=this.data.categoryId	
    let page=this.data.page
    let pageSize=this.data.pageSize
    Controller.listForLawyer({categoryId,page,pageSize}).then(res=>{
       let baseData=res.data.baseData
      
        let arr=[]
       
       baseData.list.map((item,index)=>{
        
        
        if(item.categoryTitle){
          item.categoryTitle=item.categoryTitle.split(',')
        }else{
          item.categoryTitle=[]
        }

     
      
          
           this.data.listForLawyer.push(item)
       })

       this.setData({
        listForLawyer:this.data.listForLawyer,
        isEnd:baseData.lastPage,
        isloading:false
       })
       
    })
  },
  onShareAppMessage: function (e) {
    
  },
  onShareTimeline: function(res){
    
  },
  onReachBottom:function(){
    if(this.data.isEnd){
      return
    }else{
       this.data.page=this.data.page+1
       this.getlistForLawyer()
    }
  }

})